{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Number of Burgers with No Waste of Ingredients"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Medium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数学"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: numOfBurgers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #不浪费原料的汉堡制作方案"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>圣诞活动预热开始啦，汉堡店推出了全新的汉堡套餐。为了避免浪费原料，请你帮他们制定合适的制作计划。</p>\n",
    "\n",
    "<p>给你两个整数&nbsp;<code>tomatoSlices</code>&nbsp;和&nbsp;<code>cheeseSlices</code>，分别表示番茄片和奶酪片的数目。不同汉堡的原料搭配如下：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li><strong>巨无霸汉堡：</strong>4 片番茄和 1 片奶酪</li>\n",
    "\t<li><strong>小皇堡：</strong>2 片番茄和&nbsp;1 片奶酪</li>\n",
    "</ul>\n",
    "\n",
    "<p>请你以&nbsp;<code>[total_jumbo, total_small]</code>（[巨无霸汉堡总数，小皇堡总数]）的格式返回恰当的制作方案，使得剩下的番茄片&nbsp;<code>tomatoSlices</code>&nbsp;和奶酪片&nbsp;<code>cheeseSlices</code>&nbsp;的数量都是&nbsp;<code>0</code>。</p>\n",
    "\n",
    "<p>如果无法使剩下的番茄片&nbsp;<code>tomatoSlices</code>&nbsp;和奶酪片&nbsp;<code>cheeseSlices</code>&nbsp;的数量为&nbsp;<code>0</code>，就请返回&nbsp;<code>[]</code>。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>tomatoSlices = 16, cheeseSlices = 7\n",
    "<strong>输出：</strong>[1,6]\n",
    "<strong>解释：</strong>制作 1 个巨无霸汉堡和 6 个小皇堡需要 4*1 + 2*6 = 16 片番茄和 1 + 6 = 7 片奶酪。不会剩下原料。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>tomatoSlices = 17, cheeseSlices = 4\n",
    "<strong>输出：</strong>[]\n",
    "<strong>解释：</strong>只制作小皇堡和巨无霸汉堡无法用光全部原料。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>tomatoSlices = 4, cheeseSlices = 17\n",
    "<strong>输出：</strong>[]\n",
    "<strong>解释：</strong>制作 1 个巨无霸汉堡会剩下 16 片奶酪，制作 2 个小皇堡会剩下 15 片奶酪。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 4：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>tomatoSlices = 0, cheeseSlices = 0\n",
    "<strong>输出：</strong>[0,0]\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 5：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>tomatoSlices = 2, cheeseSlices = 1\n",
    "<strong>输出：</strong>[0,1]\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>0 &lt;= tomatoSlices &lt;= 10^7</code></li>\n",
    "\t<li><code>0 &lt;= cheeseSlices &lt;= 10^7</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [number-of-burgers-with-no-waste-of-ingredients](https://leetcode.cn/problems/number-of-burgers-with-no-waste-of-ingredients/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [number-of-burgers-with-no-waste-of-ingredients](https://leetcode.cn/problems/number-of-burgers-with-no-waste-of-ingredients/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['16\\n7', '17\\n4', '4\\n17']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices < 2*cheeseSlices or tomatoSlices > 4*cheeseSlices or tomatoSlices % 2 != 0:\n",
    "            return []\n",
    "        else :\n",
    "            bigBurgers = int((tomatoSlices - 2*cheeseSlices)/2)\n",
    "            smallBurgers = cheeseSlices - bigBurgers\n",
    "            return[bigBurgers,smallBurgers]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if (tomatoSlices/2-cheeseSlices) % 1==0 and 0<=tomatoSlices/2-cheeseSlices<=cheeseSlices:\n",
    "            a=int(tomatoSlices/2-cheeseSlices)\n",
    "            b=int(cheeseSlices-a)\n",
    "            l=[a,b]\n",
    "            return l\n",
    "        else:\n",
    "            return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "\n",
    "        # ans = []\n",
    "\n",
    "        # maxlargeBurger = tomatoSlices // 4 if (tomatoSlices // 4) < cheeseSlices else cheeseSlices\n",
    "\n",
    "        # for numlargeBurger in range(maxlargeBurger + 1):\n",
    "\n",
    "        #     numlargeTomato,numlargeCheese,numsmallTomato,numsmallChesses = numlargeBurger * 4,numlargeBurger,tomatoSlices - numlargeBurger * 4,cheeseSlices - numlargeBurger\n",
    "\n",
    "        #     if (numsmallTomato % 2 == 0) and (numsmallTomato // 2 == numsmallChesses):\n",
    "        #         ans.append(numlargeBurger)\n",
    "        #         ans.append(numsmallChesses)\n",
    "        #     else:\n",
    "        #         continue\n",
    "\n",
    "        # if ans:return ans\n",
    "        # else:return []\n",
    "\n",
    "        numlargeBurger = (tomatoSlices - 2 * cheeseSlices) / 2\n",
    "        numsmallBurger = cheeseSlices - numlargeBurger\n",
    "\n",
    "        if numlargeBurger < 0 or numlargeBurger - int(numlargeBurger) != 0 or numsmallBurger < 0:return []\n",
    "        else:return [int(numlargeBurger),int(numsmallBurger)]\n",
    "\n",
    "        \n",
    "\n",
    "        # print(numlargeBurger,numsmallBurger)\n",
    "\n",
    "            \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        x=tomatoSlices-2*cheeseSlices\n",
    "        if x<0 or x%2==1:\n",
    "            return []\n",
    "        total_jumbo=x//2\n",
    "        total_small=cheeseSlices-total_jumbo\n",
    "        if total_small<0:\n",
    "            return []\n",
    "        return [total_jumbo, total_small]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if not tomatoSlices and not cheeseSlices:\n",
    "            return [0, 0]\n",
    "        elif not tomatoSlices or not cheeseSlices:\n",
    "            return []\n",
    "        tomatoSlices -= 2 * cheeseSlices\n",
    "        div, mod = divmod(tomatoSlices, 2)\n",
    "        if mod != 0 or div > cheeseSlices or tomatoSlices<0:\n",
    "            return []\n",
    "        else:\n",
    "            return [div, cheeseSlices-div]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        a, b =4*cheeseSlices-tomatoSlices, tomatoSlices-2*cheeseSlices\n",
    "        #print(a, b)\n",
    "        if a>=0 and b>=0 and a%2 == b%2 == 0:\n",
    "            return [b//2, a//2]\n",
    "        else:\n",
    "            return []\n",
    "\n",
    "\n",
    "\n",
    "        if tomatoSlices==cheeseSlices==0:\n",
    "            return [0, 0]\n",
    "        for i in range(cheeseSlices+1):\n",
    "            if 4*i+2*(cheeseSlices-i) == tomatoSlices:\n",
    "                return [i, cheeseSlices-i]\n",
    "        return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices==0 and cheeseSlices==0:\n",
    "            return [0,0]\n",
    "        if tomatoSlices-2*cheeseSlices<0 or cheeseSlices==0:\n",
    "            return []\n",
    "        x=tomatoSlices-2*cheeseSlices\n",
    "        if x%2==0 and cheeseSlices-int(x/2)>0:\n",
    "            return [int(x/2),cheeseSlices-int(x/2)]\n",
    "        else:\n",
    "            return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices & 1 == 1:\n",
    "            return []\n",
    "        if 2 * cheeseSlices <= tomatoSlices <= 4 * cheeseSlices: \n",
    "            a = (tomatoSlices - 2 * cheeseSlices) // 2\n",
    "            b = cheeseSlices - a\n",
    "            return [a, b]\n",
    "        return []\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        x=tomatoSlices-2*cheeseSlices\n",
    "        if x<0 or x%2==1:\n",
    "            return []\n",
    "        total_jumbo=x//2\n",
    "        total_small=cheeseSlices-total_jumbo\n",
    "        if total_small<0:\n",
    "            return []\n",
    "        return [total_jumbo, total_small]\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        result = []\n",
    "        if((tomatoSlices- 2 * cheeseSlices) % 2 == 0 and tomatoSlices- 2 * cheeseSlices >= 0 and 4*cheeseSlices -tomatoSlices >= 0):\n",
    "            result.append(int((tomatoSlices- 2 * cheeseSlices) / 2))\n",
    "            result.append(int((4*cheeseSlices -tomatoSlices) /2))\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices & 1:\n",
    "            return []\n",
    "        big = tomatoSlices // 2 - cheeseSlices\n",
    "        if big < 0 or big > cheeseSlices:\n",
    "            return []\n",
    "        return [big, cheeseSlices - big]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\r\n",
    "        # 4x +2y = tomatoSlices\r\n",
    "        # x + y = cheeseSlices\r\n",
    "        # 2x = tomatoSlices - 2 * cheeseSlices\r\n",
    "        x = (tomatoSlices - 2 * cheeseSlices) / 2\r\n",
    "        y = cheeseSlices - x\r\n",
    "        if x < 0 or y < 0 or x % 1 != 0 or y % 1 != 0:\r\n",
    "            return []\r\n",
    "        return [int(x), int(y)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices % 2 == 1 or tomatoSlices < 2 * cheeseSlices or tomatoSlices > 4 * cheeseSlices :\n",
    "            return []\n",
    "        a = (tomatoSlices >> 1) - cheeseSlices\n",
    "        return[a, cheeseSlices - a]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices % 2 != 0 or tomatoSlices < 2 * cheeseSlices or cheeseSlices * 4 < tomatoSlices:\n",
    "            return []\n",
    "        return [tomatoSlices//2 - cheeseSlices, cheeseSlices * 2- tomatoSlices//2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        a, b =4*cheeseSlices-tomatoSlices, tomatoSlices-2*cheeseSlices\n",
    "        #print(a, b)\n",
    "        if a>=0 and b>=0 and a%2 == b%2 == 0:\n",
    "            return [b//2, a//2]\n",
    "        return []\n",
    "\n",
    "\n",
    "\n",
    "        if tomatoSlices==cheeseSlices==0:\n",
    "            return [0, 0]\n",
    "        for i in range(cheeseSlices+1):\n",
    "            if 4*i+2*(cheeseSlices-i) == tomatoSlices:\n",
    "                return [i, cheeseSlices-i]\n",
    "        return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        total_jumbo = (tomatoSlices - 2 * cheeseSlices) / 2\n",
    "        total_small = (4 * cheeseSlices - tomatoSlices) / 2\n",
    "        return [int(total_jumbo), int(total_small)] if total_jumbo == int(total_jumbo) and total_small == int(total_small) and total_jumbo >=0 and total_small >=0 else []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "\n",
    "        # ans = []\n",
    "\n",
    "        # maxlargeBurger = tomatoSlices // 4 if (tomatoSlices // 4) < cheeseSlices else cheeseSlices\n",
    "\n",
    "        # for numlargeBurger in range(maxlargeBurger + 1):\n",
    "\n",
    "        #     numlargeTomato,numlargeCheese,numsmallTomato,numsmallChesses = numlargeBurger * 4,numlargeBurger,tomatoSlices - numlargeBurger * 4,cheeseSlices - numlargeBurger\n",
    "\n",
    "        #     if (numsmallTomato % 2 == 0) and (numsmallTomato // 2 == numsmallChesses):\n",
    "        #         ans.append(numlargeBurger)\n",
    "        #         ans.append(numsmallChesses)\n",
    "        #     else:\n",
    "        #         continue\n",
    "\n",
    "        # if ans:return ans\n",
    "        # else:return []\n",
    "\n",
    "        numlargeBurger = (tomatoSlices - 2 * cheeseSlices) / 2\n",
    "        numsmallBurger = cheeseSlices - numlargeBurger\n",
    "\n",
    "        if numlargeBurger < 0 or numlargeBurger - int(numlargeBurger) != 0 or numsmallBurger < 0:return []\n",
    "        else:return [int(numlargeBurger),int(numsmallBurger)]\n",
    "\n",
    "            \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices & 1 or tomatoSlices < cheeseSlices << 1 or tomatoSlices > cheeseSlices << 2:\n",
    "            return []\n",
    "        big = tomatoSlices // 2 - cheeseSlices\n",
    "        return [big, cheeseSlices - big]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices & 1:\n",
    "            return []\n",
    "        tomato_remain = tomatoSlices // 2 - cheeseSlices\n",
    "        cheese_remain = 2 * cheeseSlices - tomatoSlices // 2\n",
    "        if tomato_remain < 0 or cheese_remain < 0:\n",
    "            return []\n",
    "        return [tomato_remain, cheese_remain]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices % 2 != 0 or tomatoSlices < 2 * cheeseSlices or cheeseSlices * 4 < tomatoSlices:\n",
    "            return []\n",
    "        return [tomatoSlices // 2 - cheeseSlices, 2 * cheeseSlices - tomatoSlices // 2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices % 2 != 0 or tomatoSlices < cheeseSlices * 2 or cheeseSlices * 4 < tomatoSlices:\n",
    "            return []\n",
    "        return [tomatoSlices // 2 - cheeseSlices, cheeseSlices * 2 - tomatoSlices // 2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices%2!=0 or tomatoSlices < (2*cheeseSlices) or tomatoSlices > 4*cheeseSlices:\n",
    "            return []\n",
    "        return [(tomatoSlices - cheeseSlices*2)//2,cheeseSlices-(tomatoSlices - cheeseSlices*2)//2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        m, n = tomatoSlices, cheeseSlices\n",
    "        jumbo = (m / 2) - n\n",
    "        small = 2 * n - m / 2\n",
    "        if jumbo >= 0 and small >= 0 and int(jumbo) == jumbo and int(small) == small:\n",
    "            return [int(jumbo), int(small)]\n",
    "        return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices==cheeseSlices==0:\n",
    "            return [0, 0]\n",
    "        a, b =4*cheeseSlices-tomatoSlices, tomatoSlices-2*cheeseSlices\n",
    "        #print(a, b)\n",
    "        if a>=0 and b>=0 and a%2 == b%2 == 0:\n",
    "            return [b//2, a//2]\n",
    "        else:\n",
    "            return []\n",
    "\n",
    "\n",
    "\n",
    "        if tomatoSlices==cheeseSlices==0:\n",
    "            return [0, 0]\n",
    "        for i in range(cheeseSlices+1):\n",
    "            if 4*i+2*(cheeseSlices-i) == tomatoSlices:\n",
    "                return [i, cheeseSlices-i]\n",
    "        return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if 4 * cheeseSlices < tomatoSlices:\n",
    "            return []\n",
    "        if tomatoSlices // 2 < cheeseSlices:\n",
    "            return []\n",
    "        t = tomatoSlices - 2 * cheeseSlices\n",
    "        if t < 0 or t % 2 == 1:\n",
    "            return []\n",
    "        m = t // 2\n",
    "        n = cheeseSlices - m\n",
    "        return [m, n]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        ans = []\n",
    "        if tomatoSlices % 2 == 1 or tomatoSlices < cheeseSlices:return ans\n",
    "        to = ch = 0\n",
    "        x = (4*cheeseSlices - tomatoSlices)\n",
    "        if x % 2 == 0:\n",
    "            ch = x // 2\n",
    "            to = cheeseSlices - ch\n",
    "            if ch < 0 or to < 0:return ans\n",
    "            ans.append(to)\n",
    "            ans.append(ch)\n",
    "            return ans\n",
    "        else:return ans              "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices%2!=0:\n",
    "            return []\n",
    "        tomatoSlices //= 2\n",
    "        x = tomatoSlices-cheeseSlices\n",
    "        if x<0:\n",
    "            return []\n",
    "        y = cheeseSlices-x\n",
    "        if y<0:\n",
    "            return []\n",
    "        return [x,y]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        l, r = -1, cheeseSlices + 1\n",
    "        while l + 1 < r:\n",
    "            m = (l + r) // 2\n",
    "            x = 4 * m + 2 * (cheeseSlices - m)\n",
    "            if x == tomatoSlices:\n",
    "                return [m, cheeseSlices - m]\n",
    "            elif x > tomatoSlices:\n",
    "                r = m\n",
    "            else:\n",
    "                l = m\n",
    "        return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        jumbo = (tomatoSlices / 2) - cheeseSlices\n",
    "        small = 2 * cheeseSlices - tomatoSlices / 2\n",
    "        if jumbo >= 0 and small >= 0 and int(jumbo) == jumbo and int(small) == small:\n",
    "            return [int(jumbo), int(small)]\n",
    "        return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if ((tomatoSlices - 2*cheeseSlices) % 2 == 1 or tomatoSlices < 2*cheeseSlices or cheeseSlices - (tomatoSlices - 2*cheeseSlices)//2 < 0):\n",
    "            return []\n",
    "        else:\n",
    "            return [(tomatoSlices - 2*cheeseSlices)//2, cheeseSlices - (tomatoSlices - 2*cheeseSlices)//2]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices==0 and cheeseSlices==0:\n",
    "            return [0,0]\n",
    "        \n",
    "        remain_num = tomatoSlices-cheeseSlices*2\n",
    "        if remain_num<0 or remain_num>cheeseSlices*2:\n",
    "            return []\n",
    "        \n",
    "        if not remain_num%2==0:\n",
    "            return []\n",
    "        \n",
    "        big_num = remain_num//2\n",
    "        small_num = cheeseSlices-big_num\n",
    "\n",
    "        return [big_num, small_num]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        a = tomatoSlices - 2 * cheeseSlices\n",
    "        if a < 0 or a % 2 != 0 or a//2 > cheeseSlices: return []\n",
    "        a //= 2\n",
    "        return [a,cheeseSlices-a]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if (tomatoSlices & 1 or\n",
    "                tomatoSlices < cheeseSlices << 1 or \n",
    "                tomatoSlices > cheeseSlices << 2):\n",
    "            return []\n",
    "        big = tomatoSlices // 2 - cheeseSlices\n",
    "        return [big, cheeseSlices - big]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:        \n",
    "        jumbo = (tomatoSlices-2*cheeseSlices) // 2\n",
    "        small = cheeseSlices - jumbo\n",
    "        if jumbo < 0 or small < 0 or 4*jumbo + 2*small != tomatoSlices:\n",
    "            return []\n",
    "        return [jumbo, small]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices % 2 or tomatoSlices < cheeseSlices * 2 or cheeseSlices * 4 < tomatoSlices:\n",
    "            return []\n",
    "        return [tomatoSlices // 2 - cheeseSlices, cheeseSlices * 2 - tomatoSlices // 2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices&1 or tomatoSlices > cheeseSlices*4 or tomatoSlices < cheeseSlices*2:\n",
    "            return [ ]\n",
    "        return [tomatoSlices//2-cheeseSlices, cheeseSlices*2 - tomatoSlices//2]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, n: int, m: int) -> List[int]:\n",
    "        # 4* x + 2 * (m-x) = n\n",
    "        # 2x+2m=n\n",
    "        # m - \n",
    "        if n- 2*m < 0 or n%2!=0 or 2*m-n//2 <0:\n",
    "        \treturn []\n",
    "        else:\n",
    "            if (n-2*m)%2!=0:\n",
    "                return []\n",
    "            else:\n",
    "                return [(n-2*m)//2, 2*m-n//2]\n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        dis = tomatoSlices - (cheeseSlices << 1)\n",
    "        if dis < 0 or dis & 1:\n",
    "            return []\n",
    "        x = dis >> 1\n",
    "        y = cheeseSlices - x\n",
    "        return [x, y] if x >= 0 and y >= 0 else []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\r\n",
    "\r\n",
    "class Solution:\r\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\r\n",
    "        x = (tomatoSlices - 2 * cheeseSlices) / 2\r\n",
    "        y = cheeseSlices - x\r\n",
    "\r\n",
    "        if x.is_integer() and y.is_integer() and x >= 0 and y >= 0:\r\n",
    "            return [int(x), int(y)]\r\n",
    "\r\n",
    "        return []\r\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\r\n",
    "        x, y = tomatoSlices // 2 - cheeseSlices, 2 * cheeseSlices - tomatoSlices // 2\r\n",
    "        if tomatoSlices % 2 == 0 and x >= 0 and y >= 0:\r\n",
    "            return [x, y] \r\n",
    "        else:\r\n",
    "            return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if (tomatoSlices - 2 * cheeseSlices) % 2 == 0:\n",
    "            x = (tomatoSlices - 2 * cheeseSlices) // 2\n",
    "            y = cheeseSlices - x\n",
    "            if x < 0 or y < 0:\n",
    "                return []\n",
    "            return [x, y]\n",
    "        return []\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices&1:\n",
    "            return []\n",
    "        # 首先设全做小皇堡。\n",
    "        多余番茄 = tomatoSlices - cheeseSlices*2\n",
    "        # 多余番茄大于半数是无法无法匹配数量。\n",
    "        if 多余番茄 > cheeseSlices*2 or 多余番茄 < 0:\n",
    "            return []\n",
    "        return [多余番茄//2, cheeseSlices-多余番茄//2]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices & 1 == 1:\n",
    "            return []\n",
    "        if 2 * cheeseSlices <= tomatoSlices <= 4 * cheeseSlices: \n",
    "            a = (tomatoSlices - 2 * cheeseSlices) // 2\n",
    "            b = cheeseSlices - a\n",
    "            return [a, b]\n",
    "        return []\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n",
    "        if tomatoSlices==cheeseSlices==0:\n",
    "            return [0, 0]\n",
    "        a, b =4*cheeseSlices-tomatoSlices, tomatoSlices-2*cheeseSlices\n",
    "        print(a, b)\n",
    "        if a>=0 and b>=0 and a%2 == b%2 == 0:\n",
    "            return [b//2, a//2]\n",
    "        else:\n",
    "            return []\n",
    "\n",
    "\n",
    "\n",
    "        if tomatoSlices==cheeseSlices==0:\n",
    "            return [0, 0]\n",
    "        for i in range(cheeseSlices+1):\n",
    "            if 4*i+2*(cheeseSlices-i) == tomatoSlices:\n",
    "                return [i, cheeseSlices-i]\n",
    "        return []"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
